<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Android-rsa解密服务端给的加密过的内容，利用rsa公钥解密方式解密，先decode再解密, Java,Android,前端,后台,全栈,移动端,图形图像">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Android-rsa解密服务端给的加密过的内容，利用rsa公钥解密方式解密，先decode再解密 | 穿破鞋</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 4.2.1"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">穿破鞋</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tools" class="waves-effect waves-light">
      
      <span>工具</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">穿破鞋</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tools" class="waves-effect waves-light">
			
				<i class="fas fa-fw fa-link"></i>
			
			工具
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/chuanpoxie/chuanpoxie.github.io" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/chuanpoxie/chuanpoxie.github.io" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/4.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Android-rsa解密服务端给的加密过的内容，利用rsa公钥解密方式解密，先decode再解密</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="container content">

    
    <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Android/">
                                <span class="chip bg-color">Android</span>
                            </a>
                        
                            <a href="/tags/RSA%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86/">
                                <span class="chip bg-color">RSA加密解密</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/Android/" class="post-category">
                                Android
                            </a>
                        
                            <a href="/categories/Android/%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86/" class="post-category">
                                加密解密
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-07-12
                </div>
                

                

                

                

                
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p> <strong>内容后台加密方式</strong>：Base64 encode加密 -&gt; <strong>Rsa</strong>私钥加密， 给我公钥用来解密, 实现方式参考：<a href="https://www.jianshu.com/p/41ea801eece2?tdsourcetag=s_pctim_aiomsg" target="_blank" rel="noopener">PHP实现RSA加解密</a> </p>
<p> <strong>前端界面方式</strong>：Base64 <em>decode解密-&gt;Rsa公钥解密， 参考</em> <a href="https://www.cnblogs.com/whoislcj/p/5470095.html?tdsourcetag=s_pctim_aiomsg" target="_blank" rel="noopener">Android数据加密之Rsa加密 - 总李写代码 - 博客园</a> <a href="https://blog.csdn.net/qq_36347817/article/details/89357281" target="_blank" rel="noopener">CSDN-专业IT技术社区-登录</a> <a href="https://www.jianshu.com/p/44b3f5f03c78" target="_blank" rel="noopener">Android加密算法</a>-我参考这个修改完善了了之前其他资料的公钥分块解密。。</p>
<p>  最后从调用方式<strong>提供工具类</strong>：- 如果你的遇到一些问题，比较后台加密方式不同，你需要查阅资料修改一些获取公钥的一些参数，有时候也会有错误提示。我没具体研究加密，就没有怎么深入。。。。喵…</p>
<p><a href="http://rsadatautil.java/" target="_blank" rel="noopener">RsaDataUtil.java</a>  - 注意这个方法CryptorNatvie.getPubliscKey(MyApplication.getInstance())/<em>GlobalAppInfo.public_key</em>/)是我获取本地so里面的一个<strong>rsa</strong>公钥的方式。你可以直接替换为自己的公钥字符串。 </p>
<pre><code>    /**
*@Author: hl
*@Date: created at 2019/12/25 11:43
*@Description: 获取RAS加密内容工具
*/
public class RsaDataUtil {

    /**
     * 解密RAS字符串
     * @param originStr
     * @return
     */
    public static String getContentByRSA(String originStr) {
        try {
            byte[] bytes = RSAUtil.decryptWithPublicKeyBlock(
                    Base64Util.decodeToBytes(originStr),
                    CryptorNatvie.getPubliscKey(MyApplication.getInstance())/*GlobalAppInfo.public_key*/);
            return new String(bytes, &quot;UTF-8&quot;);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return &quot;&quot;;
    }
}</code></pre><p><a href="http://rsautil.java/" target="_blank" rel="noopener">RSAUtil.java</a>  - 具体的Rsa加密解密方式，我这里重点关注decryptWithPublicKeyBlock</p>
<pre><code>import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

/**
 * @Author: hl
 * @Date: created at 2019/12/25 11:02
 * @Description: RSA加密解密工具
 */
public class RSAUtil {
    /**
     * 某些时候，后台(目前php后台)给的公钥并不支持RSA/ECB/PKCS1Padding算法，所以我们只需要RSA算法来通过公钥获取解密的key
     * 因此：分开两个变量使用
     */
    private static String ECB_PADDING = &quot;RSA/ECB/PKCS1Padding&quot;;
    private static String RSA = &quot;RSA&quot;;

    /**
     * RSA算法规定：待加密的字节数不能超过密钥的长度值除以8再减去11。
     * 而加密后得到密文的字节数，正好是密钥的长度值除以 8。
     */
    private static int KEYSIZE = 2048;// 密钥位数
    private static int RESERVE_BYTES = 11;
    private static int DECRYPT_BLOCK = KEYSIZE / 8;
    private static int ENCRYPT_BLOCK = DECRYPT_BLOCK - RESERVE_BYTES;

    /**
     * 随机生成RSA密钥对范围：512～2048
     * (默认密钥长度为1024)
     */
    public static KeyPair generateRSAKeyPair() {
        return generateRSAKeyPair(1024);
    }

    /**
     * 随机生成RSA密钥对
     */
    public static KeyPair generateRSAKeyPair(int keyLength) {
        try {
            KeyPairGenerator kpg = KeyPairGenerator.getInstance(RSA);
            kpg.initialize(keyLength);
            return kpg.genKeyPair();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 用公钥加密
     */
    public static byte[] encryptDataPublic(byte[] data, PublicKey publicKey) {

        try {
            // 对数据加密
            Cipher cipher = Cipher.getInstance(RSA);
            // 编码前设定编码方式及密钥
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            // 传入编码数据并返回编码结果
            return cipher.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 用公钥解密 - 传PublicKey的方式
     */
    public static byte[] decryptDataPublic(byte[] data, PublicKey publicKey) {

        try {
            // 对数据解密
            Cipher cipher = Cipher.getInstance(RSA);
            cipher.init(Cipher.DECRYPT_MODE, publicKey);
            return cipher.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 分块公钥加密
     *
     * @param data
     * @param key
     */
    public static byte[] encryptWithPublicKeyBlock(byte[] data, byte[] key) throws Exception {
        int blockCount = (data.length / ENCRYPT_BLOCK);

        if ((data.length % ENCRYPT_BLOCK) != 0) {
            blockCount += 1;
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream(blockCount * ENCRYPT_BLOCK);
        Cipher cipher = Cipher.getInstance(ECB_PADDING);
        cipher.init(Cipher.ENCRYPT_MODE, getPublicKey(key));

        for (int offset = 0; offset &lt; data.length; offset += ENCRYPT_BLOCK) {
            int inputLen = (data.length - offset);
            if (inputLen &gt; ENCRYPT_BLOCK) {
                inputLen = ENCRYPT_BLOCK;
            }
            byte[] encryptedBlock = cipher.doFinal(data, offset, inputLen);
            bos.write(encryptedBlock);
        }

        bos.close();
        return bos.toByteArray();
    }

    /**
     * 用公钥解密 - 传字符串的方式
     * ECB_PADDING--当前我的php后台数据加密方式
     */
    public static byte[] decryptDataPublic(byte[] data, String _publicKey) {

        try {
            PublicKey publicKey = loadPublicKey(_publicKey);
            // 对数据解密
            Cipher cipher = Cipher.getInstance(ECB_PADDING);
            cipher.init(Cipher.DECRYPT_MODE, publicKey);
            byte[] resultBytes = cipher.doFinal(data);
            return resultBytes;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 分块公钥解密
     *
     * @param data
     * @param key
     */
    public static byte[] decryptWithPublicKeyBlock(byte[] data, byte[] key) throws Exception {
        int blockCount = (data.length / DECRYPT_BLOCK);
        if ((data.length % DECRYPT_BLOCK) != 0) {
            blockCount += 1;
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream(blockCount * DECRYPT_BLOCK);
        Cipher cipher = Cipher.getInstance(ECB_PADDING);
        cipher.init(Cipher.DECRYPT_MODE, getPublicKey(key));
        for (int offset = 0; offset &lt; data.length; offset += DECRYPT_BLOCK) {
            int inputLen = (data.length - offset);
            if (inputLen &gt; DECRYPT_BLOCK) {
                inputLen = DECRYPT_BLOCK;
            }
            byte[] decryptedBlock = cipher.doFinal(data, offset, inputLen);
            bos.write(decryptedBlock);
        }

        bos.close();
        return bos.toByteArray();
    }

    /**
     * 分块公钥解密
     *
     * @param data
     * @param _publicKey
     */
    public static byte[] decryptWithPublicKeyBlock(byte[] data, String _publicKey) throws Exception {
        int blockCount = (data.length / DECRYPT_BLOCK);
        if ((data.length % DECRYPT_BLOCK) != 0) {
            blockCount += 1;
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream(blockCount * DECRYPT_BLOCK);
        Cipher cipher = Cipher.getInstance(ECB_PADDING);
        cipher.init(Cipher.DECRYPT_MODE, loadPublicKey(_publicKey));
        for (int offset = 0; offset &lt; data.length; offset += DECRYPT_BLOCK) {
            int inputLen = (data.length - offset);
            if (inputLen &gt; DECRYPT_BLOCK) {
                inputLen = DECRYPT_BLOCK;
            }
            byte[] decryptedBlock = cipher.doFinal(data, offset, inputLen);
            bos.write(decryptedBlock);
        }

        bos.close();
        return bos.toByteArray();
    }

    /**
     * 用私钥加密
     */
    public static byte[] encryptDataPrivate(byte[] data, PrivateKey privateKey) {
        try {
            // 对数据加密
            Cipher cipher = Cipher.getInstance(&quot;RSA/ECB/PKCS1Padding&quot;);
            cipher.init(Cipher.ENCRYPT_MODE, privateKey);

            return cipher.doFinal(data);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 分块私钥加密
     *
     * @param data
     * @param key
     */
    public static byte[] encryptWithPrivateKeyBlock(byte[] data, byte[] key) throws Exception {
        int blockCount = (data.length / ENCRYPT_BLOCK);

        if ((data.length % ENCRYPT_BLOCK) != 0) {
            blockCount += 1;
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream(blockCount * ENCRYPT_BLOCK);
        Cipher cipher = Cipher.getInstance(ECB_PADDING);
        cipher.init(Cipher.ENCRYPT_MODE, getPrivateKey(key));

        for (int offset = 0; offset &lt; data.length; offset += ENCRYPT_BLOCK) {
            int inputLen = (data.length - offset);
            if (inputLen &gt; ENCRYPT_BLOCK) {
                inputLen = ENCRYPT_BLOCK;
            }
            byte[] encryptedBlock = cipher.doFinal(data, offset, inputLen);
            bos.write(encryptedBlock);
        }

        bos.close();
        return bos.toByteArray();
    }

    /**
     * 用私钥解密
     */
    public static byte[] decryptDataPrivate(byte[] data, PrivateKey privateKey) {
        try {
            // 对数据解密
            Cipher cipher = Cipher.getInstance(&quot;RSA/ECB/PKCS1Padding&quot;);
            cipher.init(Cipher.DECRYPT_MODE, privateKey);
            return cipher.doFinal(data);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 分块私钥解密
     *
     * @param data
     * @param key
     */
    public static byte[] decryptWithPrivateKeyBlock(byte[] data, byte[] key) throws Exception {
        int blockCount = (data.length / DECRYPT_BLOCK);
        if ((data.length % DECRYPT_BLOCK) != 0) {
            blockCount += 1;
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream(blockCount * DECRYPT_BLOCK);
        Cipher cipher = Cipher.getInstance(ECB_PADDING);
        cipher.init(Cipher.DECRYPT_MODE, getPrivateKey(key));
        for (int offset = 0; offset &lt; data.length; offset += DECRYPT_BLOCK) {
            int inputLen = (data.length - offset);

            if (inputLen &gt; DECRYPT_BLOCK) {
                inputLen = DECRYPT_BLOCK;
            }

            byte[] decryptedBlock = cipher.doFinal(data, offset, inputLen);
            bos.write(decryptedBlock);
        }

        bos.close();
        return bos.toByteArray();
    }

    /**
     * 通过公钥byte[](publicKey.getEncoded())将公钥还原，适用于RSA算法
     *
     * @param keyBytes
     * @return
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
    public static PublicKey getPublicKey(byte[] keyBytes) throws NoSuchAlgorithmException,
            InvalidKeySpecException {
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance(RSA);
        PublicKey publicKey = keyFactory.generatePublic(keySpec);
        return publicKey;
    }

    /**
     * 通过私钥byte[]将公钥还原，适用于RSA算法
     *
     * @param keyBytes
     * @return
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
    public static PrivateKey getPrivateKey(byte[] keyBytes) throws NoSuchAlgorithmException,
            InvalidKeySpecException {
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance(RSA);
        PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
        return privateKey;
    }


    /**
     * 使用N、e值还原公钥
     *
     * @param modulus
     * @param publicExponent
     * @return
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
    public static PublicKey getPublicKey(String modulus, String publicExponent)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        BigInteger bigIntModulus = new BigInteger(modulus);
        BigInteger bigIntPrivateExponent = new BigInteger(publicExponent);
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus, bigIntPrivateExponent);
        KeyFactory keyFactory = KeyFactory.getInstance(RSA);
        PublicKey publicKey = keyFactory.generatePublic(keySpec);
        return publicKey;
    }

    /**
     * 使用N、d值还原私钥
     *
     * @param modulus
     * @param privateExponent
     * @return
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
    public static PrivateKey getPrivateKey(String modulus, String privateExponent)
            throws NoSuchAlgorithmException, InvalidKeySpecException {
        BigInteger bigIntModulus = new BigInteger(modulus);
        BigInteger bigIntPrivateExponent = new BigInteger(privateExponent);
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus, bigIntPrivateExponent);
        KeyFactory keyFactory = KeyFactory.getInstance(RSA);
        PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
        return privateKey;
    }

    /**
     * 从字符串中加载公钥
     *
     * @param publicKeyStr 公钥数据字符串
     * @throws Exception 加载公钥时产生的异常
     *                   RSA - 当前我的后台给的公钥的生成算法是RSA
     */
    public static PublicKey loadPublicKey(String publicKeyStr) throws Exception {
        try {
            byte[] buffer = Base64Util.decode(publicKeyStr);
            KeyFactory keyFactory = KeyFactory.getInstance(RSA);
            X509EncodedKeySpec keySpec = new X509EncodedKeySpec(buffer);
            return keyFactory.generatePublic(keySpec);
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(&quot;无此算法&quot;);
        } catch (InvalidKeySpecException e) {
            throw new Exception(&quot;公钥非法&quot;);
        } catch (NullPointerException e) {
            throw new Exception(&quot;公钥数据为空&quot;);
        }
    }

    /**
     * 从字符串中加载私钥&lt;br&gt;
     * 加载时使用的是PKCS8EncodedKeySpec（PKCS#8编码的Key指令）。
     *
     * @param privateKeyStr
     * @return
     * @throws Exception
     */
    public static PrivateKey loadPrivateKey(String privateKeyStr) throws Exception {
        try {
            byte[] buffer = Base64Util.decode(privateKeyStr);
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(buffer);
            KeyFactory keyFactory = KeyFactory.getInstance(RSA);
            return keyFactory.generatePrivate(keySpec);
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(&quot;无此算法&quot;);
        } catch (InvalidKeySpecException e) {
            throw new Exception(&quot;私钥非法&quot;);
        } catch (NullPointerException e) {
            throw new Exception(&quot;私钥数据为空&quot;);
        }
    }


    /**
     * 从文件中输入流中加载公钥
     *
     * @param in 公钥输入流
     * @throws Exception 加载公钥时产生的异常
     */
    public static PublicKey loadPublicKey(InputStream in) throws Exception {
        try {
            return loadPublicKey(readKey(in));
        } catch (IOException e) {
            throw new Exception(&quot;公钥数据流读取错误&quot;);
        } catch (NullPointerException e) {
            throw new Exception(&quot;公钥输入流为空&quot;);
        }
    }

    /**
     * 从文件中加载私钥
     *
     * @param in 私钥文件名
     * @return 是否成功
     * @throws Exception
     */
    public static PrivateKey loadPrivateKey(InputStream in) throws Exception {
        try {
            return loadPrivateKey(readKey(in));
        } catch (IOException e) {
            throw new Exception(&quot;私钥数据读取错误&quot;);
        } catch (NullPointerException e) {
            throw new Exception(&quot;私钥输入流为空&quot;);
        }
    }

    /**
     * 读取密钥信息
     *
     * @param in
     * @return
     * @throws IOException
     */
    private static String readKey(InputStream in) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String readLine = null;
        StringBuilder sb = new StringBuilder();
        while ((readLine = br.readLine()) != null) {
            if (readLine.charAt(0) == &#39;-&#39;) {
                continue;
            } else {
                sb.append(readLine);
                sb.append(&#39;\r&#39;);
            }
        }

        return sb.toString();
    }


    /**
     * 打印公钥信息
     *
     * @param publicKey
     */
    public static void printPublicKeyInfo(PublicKey publicKey) {
        RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
        System.out.println(&quot;----------RSAPublicKey----------&quot;);
        System.out.println(&quot;Modulus.length=&quot; + rsaPublicKey.getModulus().bitLength());
        System.out.println(&quot;Modulus=&quot; + rsaPublicKey.getModulus().toString());
        System.out.println(&quot;PublicExponent.length=&quot; + rsaPublicKey.getPublicExponent().bitLength());
        System.out.println(&quot;PublicExponent=&quot; + rsaPublicKey.getPublicExponent().toString());
    }

    /**
     * 打印公钥信息
     *
     * @param privateKey
     */
    public static void printPrivateKeyInfo(PrivateKey privateKey) {
        RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKey;
        System.out.println(&quot;----------RSAPrivateKey ----------&quot;);
        System.out.println(&quot;Modulus.length=&quot; + rsaPrivateKey.getModulus().bitLength());
        System.out.println(&quot;Modulus=&quot; + rsaPrivateKey.getModulus().toString());
        System.out.println(&quot;PrivateExponent.length=&quot; + rsaPrivateKey.getPrivateExponent().bitLength());
        System.out.println(&quot;PrivatecExponent=&quot; + rsaPrivateKey.getPrivateExponent().toString());

    }


    /**
     * 得到密钥字符串（经过base64编码）
     */
    public static String getKeyString(Key key) throws Exception {
        byte[] keyBytes = key.getEncoded();
        String s = Base64Util.encode(keyBytes);
        return s;
    }

    /**
     * 16进制字符串转字节数组
     *
     * @param src 16进制字符串
     * @return 字节数组
     * @throws
     */
    public static byte[] hexString2Bytes(String src) {
        int l = src.length() / 2;
        byte[] ret = new byte[l];
        for (int i = 0; i &lt; l; i++) {
            ret[i] = (byte) Integer
                    .valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
        }
        return ret;
    }

    /**
     * 16进制字符串转字符串
     *
     * @param src 16进制字符串
     * @return 字节数组
     * @throws
     */
    public static String hexString2String(String src) {
        String temp = &quot;&quot;;
        for (int i = 0; i &lt; src.length() / 2; i++) {
            temp = temp
                    + (char) Integer.valueOf(src.substring(i * 2, i * 2 + 2),
                    16).byteValue();
        }
        return temp;
    }

    /**
     * 字符串转16进制字符串
     *
     * @param strPart 字符串
     * @return 16进制字符串
     * @throws
     */
    public static String string2HexString(String strPart) {
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i &lt; strPart.length(); i++) {
            int ch = (int) strPart.charAt(i);
            String strHex = Integer.toHexString(ch);
            hexString.append(strHex);
        }
        return hexString.toString();
    }

    /**
     * 字节数组转16进制字符串
     *
     * @param b 字节数组
     * @return 16进制字符串
     * @throws
     */
    public static String bytes2HexString(byte[] b) {
        StringBuffer result = new StringBuffer();
        String hex;
        for (int i = 0; i &lt; b.length; i++) {
            hex = Integer.toHexString(b[i] &amp; 0xFF);
            if (hex.length() == 1) {
                hex = &#39;0&#39; + hex;
            }
            result.append(hex.toUpperCase());
        }
        return result.toString();
    }
}</code></pre><p><a href="http://base64util.java/" target="_blank" rel="noopener">Base64Util.java</a> - Base64解压处理，采用了android本身提供的方式</p>
<pre><code>import android.util.Base64;

import java.io.UnsupportedEncodingException;

public class Base64Util {

    /******************************************非官方**************************************/
    private static char[] base64EncodeChars = new char[]
            {&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;, &#39;H&#39;, &#39;I&#39;, &#39;J&#39;, &#39;K&#39;, &#39;L&#39;, &#39;M&#39;, &#39;N&#39;, &#39;O&#39;, &#39;P&#39;, &#39;Q&#39;, &#39;R&#39;, &#39;S&#39;, &#39;T&#39;,
                    &#39;U&#39;, &#39;V&#39;, &#39;W&#39;, &#39;X&#39;, &#39;Y&#39;, &#39;Z&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;, &#39;h&#39;, &#39;i&#39;, &#39;j&#39;, &#39;k&#39;, &#39;l&#39;, &#39;m&#39;,
                    &#39;n&#39;, &#39;o&#39;, &#39;p&#39;, &#39;q&#39;, &#39;r&#39;, &#39;s&#39;, &#39;t&#39;, &#39;u&#39;, &#39;v&#39;, &#39;w&#39;, &#39;x&#39;, &#39;y&#39;, &#39;z&#39;, &#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;,
                    &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;+&#39;, &#39;/&#39;};

    private static byte[] base64DecodeChars = new byte[]
            {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53,
                    54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
                    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29,
                    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1,
                    -1, -1, -1};

    /**
     * 加密
     *
     * @param data
     * @return
     */
    public static String encode(byte[] data) {
        return decodePublic(data);
    }

    /**
     * 解密
     *
     * @param str
     * @return
     */
    public static byte[] decode(String str) {
        try {
            return decodePrivate(str);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return new byte[]{};
    }

    private static byte[] decodePrivate(String str) throws UnsupportedEncodingException {
        StringBuffer sb = new StringBuffer();
        byte[] data = str.getBytes(&quot;US-ASCII&quot;);
        int len = data.length;
        int i = 0;
        int b1, b2, b3, b4;

        while (i &lt; len) {
            do {
                b1 = base64DecodeChars[data[i++]];
            } while (i &lt; len &amp;&amp; b1 == -1);
            if (b1 == -1)
                break;

            do {
                b2 = base64DecodeChars[data[i++]];
            } while (i &lt; len &amp;&amp; b2 == -1);
            if (b2 == -1)
                break;
            sb.append((char) ((b1 &lt;&lt; 2) | ((b2 &amp; 0x30) &gt;&gt;&gt; 4)));

            do {
                b3 = data[i++];
                if (b3 == 61)
                    return sb.toString().getBytes(&quot;iso8859-1&quot;);
                b3 = base64DecodeChars[b3];
            } while (i &lt; len &amp;&amp; b3 == -1);
            if (b3 == -1)
                break;
            sb.append((char) (((b2 &amp; 0x0f) &lt;&lt; 4) | ((b3 &amp; 0x3c) &gt;&gt;&gt; 2)));

            do {
                b4 = data[i++];
                if (b4 == 61)
                    return sb.toString().getBytes(&quot;iso8859-1&quot;);
                b4 = base64DecodeChars[b4];
            } while (i &lt; len &amp;&amp; b4 == -1);
            if (b4 == -1)
                break;
            sb.append((char) (((b3 &amp; 0x03) &lt;&lt; 6) | b4));
        }

        return sb.toString().getBytes(&quot;iso8859-1&quot;);
    }

    private static String decodePublic(byte[] data) {

        StringBuffer sb = new StringBuffer();
        int len = data.length;
        int i = 0;
        int b1, b2, b3;
        while (i &lt; len) {
            b1 = data[i++] &amp; 0xff;
            if (i == len) {
                sb.append(base64EncodeChars[b1 &gt;&gt;&gt; 2]);
                sb.append(base64EncodeChars[(b1 &amp; 0x3) &lt;&lt; 4]);
                sb.append(&quot;==&quot;);
                break;
            }
            b2 = data[i++] &amp; 0xff;
            if (i == len) {
                sb.append(base64EncodeChars[b1 &gt;&gt;&gt; 2]);
                sb.append(base64EncodeChars[((b1 &amp; 0x03) &lt;&lt; 4) | ((b2 &amp; 0xf0) &gt;&gt;&gt; 4)]);
                sb.append(base64EncodeChars[(b2 &amp; 0x0f) &lt;&lt; 2]);
                sb.append(&quot;=&quot;);
                break;
            }
            b3 = data[i++] &amp; 0xff;
            sb.append(base64EncodeChars[b1 &gt;&gt;&gt; 2]);
            sb.append(base64EncodeChars[((b1 &amp; 0x03) &lt;&lt; 4) | ((b2 &amp; 0xf0) &gt;&gt;&gt; 4)]);
            sb.append(base64EncodeChars[((b2 &amp; 0x0f) &lt;&lt; 2) | ((b3 &amp; 0xc0) &gt;&gt;&gt; 6)]);
            sb.append(base64EncodeChars[b3 &amp; 0x3f]);
        }
        return sb.toString();
    }

    /******************************************官方**************************************/
    /**
     * 【官】解密
     * @param str - 纯字母，就不搞utf-8编码了
     * @return
     */
    public static byte[] decodeToBytes(String str){
        //        try {
        //            return Base64.decode(str.getBytes(&quot;utf-8&quot;), Base64.DEFAULT);
        //        } catch (UnsupportedEncodingException e) {
        //            e.printStackTrace();
        //        }
        //        return null;
        return Base64.decode(str.getBytes(), Base64.DEFAULT);
    }
}</code></pre><p>  基本没啥问题了</p>
<p><img src="https://pic1.zhimg.com/v2-eed6af06c203c600cb743de14b17c278_b.png" alt="img"></p>
<p>  问题：</p>
<p> \1. 如果<strong>不分块解密可能会报错</strong>： - 一下不能进行太多字节解密</p>
<pre><code>  javax.crypto.IllegalBlockSizeException: input must be under 256 bytes</code></pre><p>  \2. 具体忘了，应该也是rsa获取公钥出的问题…</p>
<pre><code>java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block</code></pre><p>\3. 获取公钥方式key出问题，可能出现 ，具体是<strong>loadPublicKey(String publickey)</strong>方法，里面涉及到SSLX509Certificate等问题，这具体看后台加密的方式</p>
<pre><code> java.security.spec.InvalidKeySpecException: com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key



java.security.spec.InvalidKeySpecException: encoded key spec not recognized: failed to construct sequence from byte[]: unknown tag 13 encountered</code></pre><p>  \4. 记得公钥去掉—–BEGIN PUBLIC KEY—–  —–END PUBLIC KEY—–</p>
<p><img src="https://pic3.zhimg.com/v2-38516d96b1f82344ceff1d112625c6be_b.png" alt="img"></p>
<p>  我的格式如下（\n没去掉试哈哈，保留了，你可以去掉试试。。嘻嘻） - 我定义在<strong>cpp文件</strong>了，打包成了<strong>so</strong>，让破解更难些。。。另外加了<strong>签名校验 参考</strong> <a href="https://blog.csdn.net/venusic/article/details/52347316" target="_blank" rel="noopener">CSDN-专业IT技术社区-登录</a>，防止so直接被调用…</p>
<p><img src="https://pic2.zhimg.com/v2-6f996a159309ed70e0da7973bcb3a7dd_b.png" alt="img"></p>
<p>  <strong>cryptor.cpp</strong> - 直接给出来吧。需要可以参考</p>
<pre><code>#include &lt;jni.h&gt;
#include &lt;string&gt;

const char *app_signature_sha1=&quot;E561477307CDxxxxxxxx815EC4A014DF&quot;;
const char HexCode[]={&#39;0&#39;,&#39;1&#39;,&#39;2&#39;,&#39;3&#39;,&#39;4&#39;,&#39;5&#39;,&#39;6&#39;,&#39;7&#39;,&#39;8&#39;,&#39;9&#39;,&#39;A&#39;,&#39;B&#39;,&#39;C&#39;,&#39;D&#39;,&#39;E&#39;,&#39;F&#39;};

extern &quot;C&quot; JNIEXPORT jstring JNICALL
Java_com_lieyun_rsa_CryptorNatvie_getPubliscKey(
        JNIEnv* env,
        jclass type,
        jobject context_object) {
    jclass context_class = env-&gt;GetObjectClass(context_object);

    //context.getPackageManager()
    jmethodID methodId = env-&gt;GetMethodID(context_class, &quot;getPackageManager&quot;, &quot;()Landroid/content/pm/PackageManager;&quot;);
    jobject package_manager_object = env-&gt;CallObjectMethod(context_object, methodId);
    if (package_manager_object == NULL) {
        std::string rsa_keysbhello = &quot;hello&quot;;
        return env-&gt;NewStringUTF(rsa_keysbhello.c_str());
    }

    //context.getPackageName()
    methodId = env-&gt;GetMethodID(context_class, &quot;getPackageName&quot;, &quot;()Ljava/lang/String;&quot;);
    jstring package_name_string = (jstring)env-&gt;CallObjectMethod(context_object, methodId);
    if (package_name_string == NULL) {
        std::string rsa_keysbheys = &quot;heys&quot;;
        return env-&gt;NewStringUTF(rsa_keysbheys.c_str());
    }
    env-&gt;DeleteLocalRef(context_class);

    //PackageManager.getPackageInfo(Sting, int)
    //public static final int GET_SIGNATURES= 0x00000040;
    jclass pack_manager_class = env-&gt;GetObjectClass(package_manager_object);
    methodId = env-&gt;GetMethodID(pack_manager_class, &quot;getPackageInfo&quot;, &quot;(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;&quot;);
    env-&gt;DeleteLocalRef(pack_manager_class);
    jobject package_info_object = env-&gt;CallObjectMethod(package_manager_object, methodId, package_name_string, 0x40);
    if (package_info_object == NULL) {
        std::string rsa_keysbhey = &quot;hey&quot;;
        return env-&gt;NewStringUTF(rsa_keysbhey.c_str());
    }
    env-&gt;DeleteLocalRef(package_manager_object);

    //PackageInfo.signatures[0]
    jclass package_info_class = env-&gt;GetObjectClass(package_info_object);
    jfieldID fieldId = env-&gt;GetFieldID(package_info_class, &quot;signatures&quot;, &quot;[Landroid/content/pm/Signature;&quot;);
    env-&gt;DeleteLocalRef(package_info_class);
    jobjectArray signature_object_array = (jobjectArray)env-&gt;GetObjectField(package_info_object, fieldId);
    if (signature_object_array == NULL) {
        std::string rsa_keysbfuck = &quot;fuck&quot;;
        return env-&gt;NewStringUTF(rsa_keysbfuck.c_str());
    }
    jobject signature_object = env-&gt;GetObjectArrayElement(signature_object_array, 0);
    env-&gt;DeleteLocalRef(package_info_object);

    //Signature.toByteArray()
    jclass signature_class = env-&gt;GetObjectClass(signature_object);
    methodId = env-&gt;GetMethodID(signature_class, &quot;toByteArray&quot;, &quot;()[B&quot;);
    env-&gt;DeleteLocalRef(signature_class);
    jbyteArray signature_byte = (jbyteArray) env-&gt;CallObjectMethod(signature_object, methodId);

    //new ByteArrayInputStream - 这里报错了，但是不影响打包和运行
    jclass byte_array_input_class=env-&gt;FindClass(&quot;java/io/ByteArrayInputStream&quot;);
    methodId=env-&gt;GetMethodID(byte_array_input_class,&quot;&lt;init&gt;&quot;,&quot;([B)V&quot;);
    jobject byte_array_input=env-&gt;NewObject(byte_array_input_class,methodId,signature_byte);

    //CertificateFactory.getInstance(&quot;X.509&quot;)
    jclass certificate_factory_class=env-&gt;FindClass(&quot;java/security/cert/CertificateFactory&quot;);
    methodId=env-&gt;GetStaticMethodID(certificate_factory_class,&quot;getInstance&quot;,&quot;(Ljava/lang/String;)Ljava/security/cert/CertificateFactory;&quot;);
    jstring x_509_jstring=env-&gt;NewStringUTF(&quot;X.509&quot;);
    jobject cert_factory=env-&gt;CallStaticObjectMethod(certificate_factory_class,methodId,x_509_jstring);

    //certFactory.generateCertificate(byteIn);
    methodId=env-&gt;GetMethodID(certificate_factory_class,&quot;generateCertificate&quot;,(&quot;(Ljava/io/InputStream;)Ljava/security/cert/Certificate;&quot;));
    jobject x509_cert=env-&gt;CallObjectMethod(cert_factory,methodId,byte_array_input);
    env-&gt;DeleteLocalRef(certificate_factory_class);

    //cert.getEncoded()
    jclass x509_cert_class=env-&gt;GetObjectClass(x509_cert);
    methodId=env-&gt;GetMethodID(x509_cert_class,&quot;getEncoded&quot;,&quot;()[B&quot;);
    jbyteArray cert_byte=(jbyteArray)env-&gt;CallObjectMethod(x509_cert,methodId);
    env-&gt;DeleteLocalRef(x509_cert_class);

    //MessageDigest.getInstance(&quot;SHA1&quot;)
    jclass message_digest_class=env-&gt;FindClass(&quot;java/security/MessageDigest&quot;);
    methodId=env-&gt;GetStaticMethodID(message_digest_class,&quot;getInstance&quot;,&quot;(Ljava/lang/String;)Ljava/security/MessageDigest;&quot;);
    jstring sha1_jstring=env-&gt;NewStringUTF(&quot;SHA1&quot;);
    jobject sha1_digest=env-&gt;CallStaticObjectMethod(message_digest_class,methodId,sha1_jstring);

    //sha1.digest (certByte)
    methodId=env-&gt;GetMethodID(message_digest_class,&quot;digest&quot;,&quot;([B)[B&quot;);
    jbyteArray sha1_byte=(jbyteArray)env-&gt;CallObjectMethod(sha1_digest,methodId,cert_byte);
    env-&gt;DeleteLocalRef(message_digest_class);

    //toHexString
    jsize array_size=env-&gt;GetArrayLength(sha1_byte);
    jbyte* sha1 =env-&gt;GetByteArrayElements(sha1_byte,NULL);
    char *hex_sha=new char[array_size*2+1];
    for (int i = 0; i &lt;array_size ; ++i) {
        hex_sha[2*i]=HexCode[((unsigned char)sha1[i])/16];
        hex_sha[2*i+1]=HexCode[((unsigned char)sha1[i])%16];
    }
    hex_sha[array_size*2]=&#39;\0&#39;;
    //比较签名
    if (strcmp(hex_sha,app_signature_sha1)==0)
    {
        std::string rsa_key = &quot;MIIBIjxxxxxxxB\n&quot;;
        return env-&gt;NewStringUTF(rsa_key.c_str());
    } else{
        std::string rsa_keysb = &quot;sb&quot;;
        return env-&gt;NewStringUTF(rsa_keysb.c_str());
    }
}

//jobject getApplication(JNIEnv *env) {
//    jclass localClass = (*env)-&gt;FindClass(env,&quot;android/app/ActivityThread&quot;);
//    if (localClass!=NULL)
//    {
//        // LOGI(&quot;class have find&quot;);
//        jmethodID getapplication = (*env)-&gt;GetStaticMethodID(env,localClass, &quot;currentApplication&quot;, &quot;()Landroid/app/Application;&quot;);
//        if (getapplication!=NULL)
//        {
//            jobject application = (*env)-&gt;CallStaticObjectMethod(env,localClass, getapplication);
//            return application;
//        }
//        return NULL;
//    }
//    return NULL;
//}

//void exitApplication(JNIEnv *env, jint flag){
//    jclass temp_clazz = NULL;
//    jmethodID mid_static_method;
//    // 1、从classpath路径下搜索ClassMethod这个类，并返回该类的Class对象
//    temp_clazz =(*env)-&gt;FindClass(env,&quot;java/lang/System&quot;);
//    mid_static_method = (*env)-&gt;GetStaticMethodID(env,temp_clazz,&quot;exit&quot;,&quot;(I)V&quot;);
//    (*env)-&gt;CallStaticVoidMethod(env,temp_clazz,mid_static_method,flag);
//    (*env)-&gt;DeleteLocalRef(env,temp_clazz);
//}</code></pre><p><img src="https://pic3.zhimg.com/v2-cb671f4b8eb2f4ca168bfe673850cb76_b.png" alt="img"></p>
<p>上面这是<strong>签名文件的sha1值</strong>，替换自己的</p>
<p><img src="https://pic1.zhimg.com/v2-5c784bf030867f88006efeba0c261fe0_b.png" alt="img"></p>
<p>上面这是rsa公钥字符串（处理了begin和end。。\n保留了。如果有问题可以再多调试）</p>
<p> 到此基本就搞定了rsa界面，然后做了基本的so加密处理 <a href="https://zhuanlan.zhihu.com/p/101999563。。。顺便复习了下native编程。。哇咔咔。。。加油。。" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/101999563。。。顺便复习了下native编程。。哇咔咔。。。加油。。</a></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">HuangLei</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://chuanpoxie.com/2020/07/12/Android-rsa%E8%A7%A3%E5%AF%86%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%BB%99%E7%9A%84%E5%8A%A0%E5%AF%86%E8%BF%87%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%8C%E5%88%A9%E7%94%A8rsa%E5%85%AC%E9%92%A5%E8%A7%A3%E5%AF%86%E6%96%B9%E5%BC%8F%E8%A7%A3%E5%AF%86%EF%BC%8C%E5%85%88decode%E5%86%8D%E8%A7%A3%E5%AF%86/">https://chuanpoxie.com/2020/07/12/Android-rsa%E8%A7%A3%E5%AF%86%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%BB%99%E7%9A%84%E5%8A%A0%E5%AF%86%E8%BF%87%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%8C%E5%88%A9%E7%94%A8rsa%E5%85%AC%E9%92%A5%E8%A7%A3%E5%AF%86%E6%96%B9%E5%BC%8F%E8%A7%A3%E5%AF%86%EF%BC%8C%E5%85%88decode%E5%86%8D%E8%A7%A3%E5%AF%86/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">HuangLei</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Android/">
                                    <span class="chip bg-color">Android</span>
                                </a>
                            
                                <a href="/tags/RSA%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86/">
                                    <span class="chip bg-color">RSA加密解密</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2020/07/12/Android-%E6%A8%A1%E5%9D%97%E5%8C%96%E3%80%81%E7%BB%84%E4%BB%B6%E5%8C%96%E3%80%81%E6%8F%92%E4%BB%B6%E5%8C%96%E3%80%81%E7%83%AD%E4%BF%AE%E5%A4%8D-%E6%80%BB%E7%BB%93%E7%9B%AE%E5%BD%95/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/3.jpg" class="responsive-img" alt="Android-模块化、组件化、插件化、热修复(总结目录)">
                        
                        <span class="card-title">Android-模块化、组件化、插件化、热修复(总结目录)</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            应网友需求，做个目录链接总结，依次进阶！
MonkeyLei：Android-模块化、组件化、插件化、热修复-国庆前瞄一眼概念啥的，好伐! 
MonkeyLei：Android-模块化、组件化、插件化、热修复-组件化一下试试 
Monkey
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-07-12
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Android/" class="post-category">
                                    Android
                                </a>
                            
                            <a href="/categories/Android/%E6%A1%86%E6%9E%B6/" class="post-category">
                                    框架
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Android/">
                        <span class="chip bg-color">Android</span>
                    </a>
                    
                    <a href="/tags/%E7%BB%84%E4%BB%B6%E5%8C%96/">
                        <span class="chip bg-color">组件化</span>
                    </a>
                    
                    <a href="/tags/%E6%8F%92%E4%BB%B6%E5%8C%96/">
                        <span class="chip bg-color">插件化</span>
                    </a>
                    
                    <a href="/tags/%E7%83%AD%E4%BF%AE%E5%A4%8D/">
                        <span class="chip bg-color">热修复</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2020/07/12/Android-androidx-ViewPager2%E5%85%A5%E9%97%A8%E7%AE%80%E4%BB%8B-%E6%80%BB%E7%BB%93%E8%AE%B0%E5%BD%95/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/4.jpg" class="responsive-img" alt="Android-androidx-ViewPager2入门简介(总结记录)">
                        
                        <span class="card-title">Android-androidx-ViewPager2入门简介(总结记录)</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Android-androidx-ViewPager2
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-07-12
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Android/" class="post-category">
                                    Android
                                </a>
                            
                            <a href="/categories/Android/Jetpack/" class="post-category">
                                    Jetpack
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Android/">
                        <span class="chip bg-color">Android</span>
                    </a>
                    
                    <a href="/tags/ViewPaper2/">
                        <span class="chip bg-color">ViewPaper2</span>
                    </a>
                    
                    <a href="/tags/%E6%8A%96%E9%9F%B3/">
                        <span class="chip bg-color">抖音</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2020</span>
            <a href="/about" target="_blank">Chuan Po Xie</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <span id="sitetime">载入运行时间...</span>
            <script>
                function siteTime() {
                    var seconds = 1000;
                    var minutes = seconds * 60;
                    var hours = minutes * 60;
                    var days = hours * 24;
                    var years = days * 365;
                    var today = new Date();
                    var startYear = "2020";
                    var startMonth = "7";
                    var startDate = "1";
                    var startHour = "0";
                    var startMinute = "0";
                    var startSecond = "0";
                    var todayYear = today.getFullYear();
                    var todayMonth = today.getMonth() + 1;
                    var todayDate = today.getDate();
                    var todayHour = today.getHours();
                    var todayMinute = today.getMinutes();
                    var todaySecond = today.getSeconds();
                    var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                    var diff = t2 - t1;
                    var diffYears = Math.floor(diff / years);
                    var diffDays = Math.floor((diff / days) - diffYears * 365);
                    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
                    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
                        minutes);
                    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours -
                        diffMinutes * minutes) / seconds);
                    if (startYear == todayYear) {
                        document.getElementById("year").innerHTML = todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffDays + " 天 " + diffHours +
                            " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    } else {
                        document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                        document.getElementById("sitetime").innerHTML = "本站已安全运行 " + diffYears + " 年 " + diffDays +
                            " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
                    }
                }
                setInterval(siteTime, 1000);
            </script>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/chuanpoxie/chuanpoxie.github.io" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:just_test@live.cn" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=642419907" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 642419907" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
